﻿using System.Data;

namespace DataScripter.Scripting.Processes.Morphs
{
    public class CopyMorphAction : BaseFieldMorphAction
    {
        #region Overrides of BaseFieldMorphAction

        public override void Apply(DataTable from, DataTable to)
        {
            foreach (DataColumn column in from.Columns)
            {
                if (ShouldBeAppliedOnField(column.ColumnName))
                {
                    to.Columns.Add(column.ColumnName, column.DataType, column.Expression);
                }
            }
        }

        public override void Apply(DataRow @from, DataRow to, DataTable fromTable, DataTable targetTable)
        {
            foreach (DataColumn column in fromTable.Columns)
            {
                string columnName = column.ColumnName;
                if (ShouldBeAppliedOnField(columnName))
                {
                    to[columnName] = from[columnName];
                }
            }
        }

        #endregion
    }
}
